<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class AdminRestore extends Command
{
    protected $signature = 'admin:restore';

    protected $description = '还原后台相关数据, 菜单、权限等';

    protected $seeders = [
        'MenusTableSeeder',
        'RoleAccessTableSeeder',
        'RolePermissionsTableSeeder',
        'RolesTableSeeder',
        // 'RoleUsersTableSeeder',
    ];

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $bar = $this->output->createProgressBar(count($this->seeders));
        $bar->start();

        foreach ($this->seeders as $seeder) {
            $this->callSilent('db:seed', [
                'class' => $seeder,
                '--force' => true,
            ]);

            $bar->advance();
        }

        // 清空角色权限缓存等数据
        $this->call('cache:reset');

        $bar->finish();

        $this->line("\n");
        $this->info('restore success');
    }
}
